import { createStore } from '@/airstore';
import ApiClient from '@/services/apiClient';

export default createStore({
  namespace: 'InstructShipStore',
  contractInstruct: {
    search: '',
    list: [],
  },
  workInstruct: {
    list: [],
  },
  instructDetails: [],
  setContract(instruct) {
    this.contractInstruct = { ...this.contractInstruct, ...instruct };
  },
  /**
   * 根据筛选信息获取合同发料指令
   *
   * @param {*} contractSearch
   */
  async searchByFuzzyContract(contractSearch) {
    const srRes = await ApiClient.get(
      `amUser/v1/unimplement/${contractSearch}`,
    );
    this.setContract({
      list: [
        {
          id: 1,
          title: 'JCA-ASGG-123-1DDS',
          desc: 'XXXXX工作指令描述XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX... ',
        },
        {
          id: 2,
          title: 'JCA-ASGG-223-1DDS',
          desc: 'XXXXX工作指令描述XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX... ',
        },
      ], //srRes.data,
    });
  },
  setWorksInstruct(instruct) {
    this.workInstruct = { ...this.workInstruct, ...instruct };
  },
  /**
   * 根据发料人tid加载工作发料指令列表
   *
   * @param {*} requesterTid
   */
  async loadWorkInstructs(requesterTid) {
    const srRes = await ApiClient.get(`amUser/v1/unimplement/${requesterTid}`);
    this.setWorksInstruct({
      list: [
        {
          id: 1,
          title: 'JCA-ASGG-123-1DDS',
          desc: 'XXXXX工作指令描述XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX... ',
        },
        {
          id: 2,
          title: 'JCA-ASGG-223-1DDS',
          desc: 'XXXXX工作指令描述XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX... ',
        },
      ], //srRes.data,
    });
  },
  setInstructDetails(details) {
    this.instructDetails = details;
  },
  async getShipDetails(instructTid) {
    const srRes = await ApiClient.get(`amUser/v1/unimplement/${instructTid}`);
    this.setInstructDetails([
      {
        id: 1,
        pn: 'Pn-test-1234',
        count: 10,
        rackno: '13-A--1=1',
        children: {
          locks: [
            {
              id: 1,
              pn: 'Pn1',
              sn: 'sn1',
              count: 10,
              rackno: '13-A--1=1',
              date: '2020-09-01',
            },
            {
              id: 2,
              pn: 'Pn2',
              sn: 'sn2',
              count: 10,
              rackno: '13-A--1=1',
              date: '2020-09-02',
            },
          ],
          avails: [
            {
              id: 1,
              pn: 'Pn1',
              sn: 'sn1',
              count: 10,
              rackno: '13-A--1=1',
              date: '2020-09-01',
            },
            {
              id: 2,
              pn: 'Pn2',
              sn: 'sn2',
              count: 10,
              rackno: '13-A--1=1',
              date: '2020-09-02',
            },
          ],
        },
      },
      {
        id: 2,
        pn: 'Pn-test-2354',
        count: 7,
        rackno: '13-A--2=1',
        children: {
          locks: [
            {
              id: 1,
              pn: 'Pn1',
              sn: 'sn1',
              count: 10,
              rackno: '13-A--1=1',
              date: '2020-09-01',
            },
            {
              id: 2,
              pn: 'Pn2',
              sn: 'sn2',
              count: 10,
              rackno: '13-A--1=1',
              date: '2020-09-02',
            },
          ],
          avails: [
            {
              id: 1,
              pn: 'Pn1',
              sn: 'sn1',
              count: 10,
              rackno: '13-A--1=1',
              date: '2020-09-01',
            },
            {
              id: 2,
              pn: 'Pn2',
              sn: 'sn2',
              count: 10,
              rackno: '13-A--1=1',
              date: '2020-09-02',
            },
          ],
        },
      },
    ]);
  },
  async getShipBoxDetails(boxPara) {
    const srRes = await ApiClient.get(`amUser/v1/unimplement/${boxPara}`);
  },
});
